package com.leyou.sms.listener;
import com.leyou.sms.Utils.LySMSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.Map;


@Slf4j
@Component
public class MessageListener {
    @Autowired
    private LySMSUtils smsUtils;
    //获取user发送的mq的信息，再通过阿里通信服务发送消息到用户手机
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "verifyQueue", durable = "true"),
            exchange = @Exchange(name = "leyou", type = ExchangeTypes.TOPIC),
            key = "verify"
    ))
    public void listenVerifyCodeMessage(Map<String,String> msg){
        System.out.println(msg);
        smsUtils.sendCode(msg.get("phone"),msg.get("code"));
    }
}